package infostroy.bookagolf.components.panels;

import infostroy.bookagolf.common.Constants.Colors;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;

/**
 * Created by valer_000 on 2/27/14.
 */
public class GolfRightRoundPanel extends JPanel{
    public static final int rounding = 8;

    public GolfRightRoundPanel() {
        setOpaque(false);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D graphics = (Graphics2D)g;
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        GeneralPath generalPath = new GeneralPath();
        //Rounded top left corner
        generalPath.moveTo(0, rounding / 2);
        generalPath.quadTo(0, 0, rounding / 2, 0);
        //We don't need to round top right corner. So just move to end.
        generalPath.lineTo(getWidth(), 0);
        //Going bottom right corner
        generalPath.lineTo(getWidth(), getHeight());
        //Going bottom left corner
        generalPath.lineTo(rounding / 2, getHeight());
        generalPath.quadTo(0, getHeight(), 0, getHeight () - rounding / 2);
        //Connecting bottom left and top left corners
        generalPath.lineTo(0, rounding / 2);

        graphics.setColor(Colors.WHITE);
        graphics.fill(generalPath);

        //adding top shadow
        GradientPaint gradient = new GradientPaint(0, 0, Colors.TEXT_SHADOW_START, 0, 5, Colors.TEXT_SHADOW_END);
        graphics.setPaint(gradient);
        graphics.fill(generalPath);
    }
}
